package com.buka.controller;

import com.buka.domain.ResponseResult;
import com.buka.dto.TagListDto;
import com.buka.pojo.Tag;
import com.buka.service.TagService;
import com.buka.vo.TagVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TagController {
    @Autowired
    private TagService tagService;

    @GetMapping("/content/tag/listAllTag")
    public ResponseResult listAllTag() {
        List<TagVo> list = tagService.listAllTag();
        return ResponseResult.okResult(list);
    }

    @GetMapping("/content/tag/list")
    public ResponseResult list(Integer pageNum, Integer pageSize, TagListDto tagListDto) {
        return tagService.pageTagList(pageNum, pageSize, tagListDto);
    }

    @PostMapping("/content/tag")
    public ResponseResult tag(@RequestBody Tag tag) {
        return tagService.add(tag);
    }

    @DeleteMapping("/content/tag/{id}")
    public ResponseResult delete(@PathVariable("id") String id) {
        return tagService.delete(id);
    }

    @GetMapping("/content/tag/{id}")
    public ResponseResult get(@PathVariable("id") String id) {
        return ResponseResult.okResult(tagService.getById(id));
    }

    @PutMapping("/content/tag")
    public ResponseResult update(@RequestBody Tag tag) {
        return tagService.put(tag);
    }

}
